﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using COMOSOFT.Class;
using System.IO;
using System.Net.Mail;

namespace COMOSOFT.OrderBusiness.Forms
{
    public partial class FrmReport : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        string reportname = null;
        public FrmReport(string reportname)
        {
            InitializeComponent();
            this.reportname = reportname;
            switch (reportname)
            {
                case "rptOrderDetais":
                Report.rptOrderDetais rptOD = new Report.rptOrderDetais(ClassShare.fpid, ClassShare.OIDs);                
                documentViewer1.DocumentSource = rptOD;               
                break;
                case "rptFtyPurMaster":
                Report.rptFtyPurMaster rptFPM = new Report.rptFtyPurMaster(ClassShare.FPMIDs,ClassShare.OIDs);
                documentViewer1.DocumentSource =rptFPM;  
                break;
            }        
        }

        private void bnt_sendemail_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                MemoryStream mem = new MemoryStream();
                if (reportname == "rptOrderDetais")
                {
                    Report.rptOrderDetais rptOD = new Report.rptOrderDetais(ClassShare.fpid, ClassShare.OIDs);                   
                    rptOD.ExportToPdf(mem);                   
                }
                else if (reportname == "rptFtyPurMaster")
                {
                    Report.rptFtyPurMaster rptFPM = new Report.rptFtyPurMaster(ClassShare.FPMIDs,ClassShare.OIDs);
                    rptFPM.ExportToPdf(mem);
                }

                mem.Seek(0, System.IO.SeekOrigin.Begin);
                Attachment att = new Attachment(mem, "SendPurchaseFactory.pdf", "application/pdf");
                FrmSendEmail frmsendmail = new FrmSendEmail();
                frmsendmail.att = att;
                frmsendmail.AddFile("SendPurchaseFactory.pdf");
                frmsendmail.ShowDialog();
                mem.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);                  
            }
        }
    }
}
